<?php
class adControl extends skymvc{
	public $sw;
	public function __construct(){
		parent::__construct();	 
	}
	
 	public function onDefault(){
		
	}
	
	public function onListbyno(){
		$no=get_post('no','h');
		$limit=get_post('limit','i');
		$limit=$limit?$limit:4;
		$data=$this->listbyno($no,$limit);
		$this->goAll("sucess",0,$data);
	}
	
	public function listbyno($no,$limit=4,$sw=false){
		$tag_id=M("ad_tags")->selectOne(array("where"=>"  tagno='".$no."'  ","fields"=>"tag_id"));
		if(!$tag_id) return false;
		 $where=" starttime<".time()."  AND endtime>".time()." AND status=2 AND (tag_id=".intval($tag_id)." or tag_id_2nd=".intval($tag_id).") ";
		if($sw){
			$where.=" AND siteid=".SITEID." ";
		}
		
		$data=M("ad")->select(array(
			"where"=>$where,
			"order"=>" orderindex asc",
			"start"=>0,
			"limit"=>$limit
		));
		if($data){
			foreach($data as $k=>$v){
				$v['info']=$v['info']?$v['info']:$v['title'];
				$v['link2']=$v['link2']?$v['link2']:$v['link1'];
				$v['imgurl']=images_site($v['imgurl']);
				
				$data[$k]=$v;
			}
		}
		 
		return $data;
	}
	
 
}

?>